import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { TilePanel } from "../../equipment/TilePanel";
import { CornucopiaCellRender } from "./CornucopiaCellRender";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { PulseSharedObject } from "../../player/PulseSharedObject";
import { SharedObjectName } from "../../common/defin/SharedObjectName";
import { Cache } from "../../../cache/Cache";
import { EFriendFlag } from "../../../../../Message/Game/EFriendFlag";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { CheckBox } from "../../../../../fl/controls/CheckBox";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class CornucopiaFriendsBlessToMeWindow
    
    export  class CornucopiaFriendsBlessToMeWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._aryPlayer = new Array<any>();
            setSize(400, 245);
            titleHeight = 26;
            title = Language.getString(40305);
            return;
        }

        protected /* override */ setWindowCenter(): void
        {
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(15, 34, 374, 172, this);
            this._friendList = new TilePanel();
            this._friendList.horizontalGap = 3;
            this._friendList.verticalGap = 3;
            this._friendList.columnWidth = 356;
            this._friendList.rowHeight = 40;
            this._friendList.setSize(356, 166);
            this._friendList.move(30, 40);
            this._friendList.setStyle("cellRenderer", CornucopiaCellRender);
            this.addChild(this._friendList);
            this._pageSelecter = new PageSelecter();
            this._pageSelecter.x = 160;
            this._pageSelecter.y = 215;
            this._pageSelecter.addEventListener(flash.events.Event.CHANGE, this.onPageChange);
            this.addChild(this._pageSelecter);
            this._checkBoxToday = ObjCreate.createCheckBox(Language.getString(40306), 20, 210, 110, 28, this);
            this._btnFeedbackBless = ObjCreate.createGButton(Language.getString(40400), 285, 210, 100, 26, this, "ButtonLarge");
            this._checkBoxToday.addEventListener(flash.events.Event.CHANGE, this.onCheckBox);
            this._btnFeedbackBless.addEventListener(flash.events.MouseEvent.CLICK, this.onClickFeedbackBless);
            return;
        }

        public updateDataProvider(arg1: Array<any>): void
        {
            this._aryPlayer = arg1;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.maxPage = Math.ceil(this._aryPlayer.length / this.pageSize);
            this._friendList.dataProvider = this.getDataProvider();
            this._friendList.drawNow();
            return;
        }

        /* internal  */getDataProvider(): DataProvider
        {
            var loc1=new Array<any>();
            var loc2=(this._pageSelecter.currentPage - 1) * this.pageSize;
            var loc3=Math.min(this._pageSelecter.currentPage * this.pageSize, this._aryPlayer.length);
            var loc4=loc2;
            while (loc4 < loc3) 
            {
                loc1.push(this._aryPlayer[loc4]);
                ++loc4;
            }
            return new DataProvider(loc1);
        }

        /* internal  */onPageChange(arg1: Object /* flash.events.Event */): void
        {
            this._friendList.dataProvider = this.getDataProvider();
            this._friendList.drawNow();
            return;
        }

        /* internal  */onCheckBox(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._checkBoxToday.selected;
            PulseSharedObject.save(SharedObjectName.CornucopiaNotTip, loc1);
            return;
        }

        /* internal  */onClickFeedbackBless(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=new Array<any>();
            var loc4=0;
            var loc5=this._aryPlayer;
            for(loc2 of loc5) 
            {
                if (!Cache.instance.friend.isFriend(loc2.playerName)) 
                {
                    continue;
                }
                if (!((loc3 = Cache.instance.friend.getFriendInfoByPlayerName(loc2.playerName, EFriendFlag._EFriendFlagFriend)) && !loc3.isCornucopiaed())) 
                {
                    continue;
                }
                loc1.push(loc2.playerId);
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaBlessAll, loc1));
            this.hide();
            return;
        }

        /* internal */ /* const */pageSize: int=4;

        /* internal */ /* var */_friendList: TilePanel;

        /* internal */ /* var */_pageSelecter: PageSelecter;

        /* internal */ /* var */_checkBoxToday: CheckBox;

        /* internal */ /* var */_btnFeedbackBless: GButton;

        /* internal */ /* var */_aryPlayer: Array<any>;
    }
